package com.maduar.mybatis.demo.controller;

import com.google.common.collect.Maps;
import com.maduar.mybatis.demo.User;
import com.maduar.mybatis.demo.service.RemoteClient;
import com.maduar.mybatis.demo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Description:
 *
 * @author maduar maduar@163.com
 * @date 2021-05-12 23:22
 */
@RestController
@RequestMapping("/feign")
public class MyFeignController {

    @Autowired
    private RemoteClient remoteClient;

    @GetMapping("/user")
    public Result<User> getUser(@RequestParam("name") String name,
                                @RequestParam("age") int age) {
        return remoteClient.getUser(name, age);
    }

    @PostMapping("/addUser")
    public Result<User> addUser(@RequestBody User user) {
        return remoteClient.addUser(user);
    }

    @GetMapping("/getAge")
    public Result<Integer> getAge() {
        return remoteClient.getAge();
    }
    @GetMapping("/getYourAge")
    public Result<Integer> getAge(@RequestParam("age") int age) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("age", age);
        return remoteClient.getYourAge(map);
    }

}
